package com.petshop.controller;

import com.petshop.pojo.Address;
import com.petshop.service.AddressService;
import com.petshop.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("address")
@CrossOrigin
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     * 新增一条地址信息
     *
     * @param address
     * @return
     */
    @PostMapping("insertAddress")
    public Result insertAddress(@RequestBody Address address, @RequestHeader("Authorization") String token) {
        Result result = addressService.insertAddress(address, token);
        return result;
    }

    /**
     * 删除地址信息
     *
     * @param addressId
     * @return
     */
    @GetMapping("deleteAddress")
    public Result deleteAddress(Integer addressId) {
        Result result = addressService.deleteAddress(addressId);
        return result;
    }

    /**
     * 修改地址信息
     *
     * @param address
     * @return
     */
    @PostMapping("updateAddress")
    public Result updateAddress(@RequestBody Address address) {
        Result result = addressService.updateAddress(address);
        return result;
    }

    /**
     * 查询所有地址信息
     *
     * @param token
     * @return
     */
    @GetMapping("queryAddress")
    public Result queryAddress(@RequestHeader("Authorization") String token) {
        Result result = addressService.queryAddress(token);
        return result;
    }

    /**
     * 根据id查询单个地址信息
     *
     * @param addressId
     * @param token
     * @return
     */
    @GetMapping("queryOneAddress")
    public Result queryOneAddress(Integer addressId) {
        Result result = addressService.queryOneAddress(addressId);
        return result;
    }
}
